package com.yami.shop.payment.event;

import cn.hutool.core.util.StrUtil;
import com.google.gson.Gson;
import com.yami.shop.payment.dto.PassbackParamsDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;
import java.util.Objects;

@Component
public class PaymentListen {

    private static final Logger log = LoggerFactory.getLogger(PaymentListen.class);


    @Async
    @EventListener
    @Transactional
    public void paySuccess(PaymentEvent event) {
        String orderId = event.getOrderId();
        Integer type = event.getType();
        String actionMoney = event.getActionMoney();
        String passbackParams = event.getPassbackParams();

        //回传信息
        Gson gson=new Gson();
        PassbackParamsDto passbackParamsDto = gson.fromJson(passbackParams, PassbackParamsDto.class);

        String payRecordId = passbackParamsDto.getPayRecordId();
        //BPayRecord one = bPayRecordService.getById(payRecordId);

        System.out.println(orderId+" 支付成功或退款成功.....");
        if(type == 0){
            //支付成功

        }else if(type == 1){
            //退款成功
        }
    }
}
